﻿@using PagedList.Mvc;

@model PagedList.IPagedList<Product>

@section styles{
    @Styles.Render("~/Content/PagedList.css")
}

@{
    string search = ViewBag.Search;

    ViewBag.Title = "Tìm kiếm - " + search;
}

<div id="product" class="search">
    <div class="container">
        <div class="bg-content">
            <div class="bg-title">
                <h4>Tìm kiếm: "@ViewBag.Search"</h4>
            </div>
        </div>
        @if (Model.Count > 0)
        {
            int index = 0;

            <div class="form-pagelist" style="margin-bottom: 10px;">
                <div class="row">
                    <div class="col-sm-4">
                        <div class="well-sm">
                            <span class="badge">@Model.FirstItemOnPage</span>
                            - <span class="badge">@Model.LastItemOnPage</span>
                            / <span class="badge">@Model.TotalItemCount</span>
                        </div>
                    </div>
                    <div class="col-sm-8 text-right">
                        @Html.PagedListPager(Model, page => Url.Action(null, new
                        {
                            page,
                            search = search
                        }), new PagedListRenderOptions
                        {
                            LinkToFirstPageFormat = DataTableConstant.LinkToFirstPageFormat,
                            LinkToPreviousPageFormat = DataTableConstant.LinkToPreviousPageFormat,
                            LinkToNextPageFormat = DataTableConstant.LinkToNextPageFormat,
                            LinkToLastPageFormat = DataTableConstant.LinkToLastPageFormat,
                            MaximumPageNumbersToDisplay = 5
                        })
                    </div>
                </div>
            </div>
             
            <div class="row min-padding">
                @foreach (Product item in Model)
                {
                    index++;

                    <div class="col-md-4 col-sm-6 col-xs-6">
                        @Html.Action("_ProductItem", "Product", new { product = item, lazyLoad = true })
                    </div>

                    if (index % 3 == 0)
                    {
                        <div class="clearfix visible-lg visible-md"></div>
                    }
                    if (index % 2 == 0)
                    {
                        <div class="clearfix visible-sm visible-xs"></div>
                    }
                }
            </div>
            <hr />
            <div class="form-pagelist">
                <div class="row">
                    <div class="col-sm-4">
                        <div class="well-sm">
                            <span class="badge">@Model.FirstItemOnPage</span>
                            - <span class="badge">@Model.LastItemOnPage</span>
                            / <span class="badge">@Model.TotalItemCount</span>
                        </div>
                    </div>
                    <div class="col-sm-8 text-right">
                        @Html.PagedListPager(Model, page => Url.Action(null, new
                        {
                            page,
                            search = search
                        }), new PagedListRenderOptions
                        {
                            LinkToFirstPageFormat = DataTableConstant.LinkToFirstPageFormat,
                            LinkToPreviousPageFormat = DataTableConstant.LinkToPreviousPageFormat,
                            LinkToNextPageFormat = DataTableConstant.LinkToNextPageFormat,
                            LinkToLastPageFormat = DataTableConstant.LinkToLastPageFormat,
                            MaximumPageNumbersToDisplay = 5
                        })
                    </div>
                </div>
            </div>
            <br />
        }
        else
        {
            <div class="jumbotron text-center">
                <h1>Không tìm thấy sản phẩm!</h1>
                <hr />
                <p><a href="/" class="btn btn-primary btn-lg" role="button">Quay về trang chủ »</a></p>
            </div>
        }
    </div>
</div>

@section scripts{
    <script>
        $('.lazy-load').lazyload();
    </script>
}